# @Time  : 2021/7/25 15:10
# @Author: zhanfengzhen
# @Email : zhanfengzhen@126.com
# @File  : conftest.py
# !/usr/bin/env python
# -*- coding: UTF-8 -*-

#读取yaml文件，解决中文乱码问题
import os
import pytest
import yaml

from hogwarts.HogwartsHomework.pytestWork2.pythoncode.calculator import Calculator


def pytest_collection_modifyitems(items):
    """
    测试用例收集完成时，将收集到的item的name和nodeid的中文显示在控制台上
    :return:
    """
    for item in items:
        #item.name 测试用例的名字
        #item.nodeid 测试用例的路径
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")

#实例化计算器
@pytest.fixture()
def get_calculator():
    cal = Calculator()
    return cal



#获取测试数据
def getData():
    dir = os.path.dirname(__file__)  # 获取当前文件目录
    yml = os.path.join(dir, 'datas.yml')
    with open(yml, encoding='utf-8') as f:
        datas = yaml.safe_load(f)
    return datas
#获取加法数据
@pytest.fixture(params=getData()['add']['datas'], ids=getData()['add']['ids'])
def get_add_datas(request):
    return  request.param
@pytest.fixture(params=getData()['div']['datas'], ids=getData()['div']['ids'])
def get_div_datas(request):
    return request.param



@pytest.fixture(scope='class')
def setup_teardown():
    print('开始计算')
    yield None
    print('结束计算')